require('games.heroes3.h3maprw')
require('libluartk')
ud=require('uchardet')
local files=wmc.findFiles(arg[1],'.*%.h3m',true)
table_ieach(files,function(_,f)
	local ok,info
	ok,info=pcall(h3MapGetInfo,f)
	local u8f=ansi2utf8(f)
	if ok then
		local name,desc=info.name.str,info.description.str
		local encoding,lang=ud.detect(name .. ';' .. desc)
		if encoding and encoding ~= 'UTF-8' and encoding ~= 'ASCII' then
			name=iconv(encoding,'UTF-8',name) or name
			desc=iconv(encoding,'UTF-8',desc) or desc
		end
		printf('file="%s",name=%s,desc=%s,encoding="%s"',
			u8f,json.encode(name),json.encode(desc),encoding)
	else
		printk(2,'Failed on %s : %s\n',u8f,info)
		jprint{file=u8f,error='failed'}
	end
end)